<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;
class Biaozhunbianzhi extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    public function index(Request $request)
    {	
		$this->view->assign('title', __('标准编制'));
		
		$banner=Db::name('banner')->where([
			'type_data'=>0,
			'bannertype_id'=>12
		])->select();
		$this->assign('banner',$banner);
		
		$biaozhunbianzhi_type=Db::name('biaozhuntype')->order('weigh desc')->select();
		$this->assign('biaozhunbianzhi_type',$biaozhunbianzhi_type);
		
		$hangyexinxi_type2=Db::name('hangyexinxitype')->where(['id'=>['>',1],'show_switch'=>1])->order('weigh desc')->limit(3)->select();
		foreach($hangyexinxi_type2 as $k=>$v){
			$hangyexinxi_type2[$k]['list']=Db::name('hangyexinxi')->where(['type_id'=>$v['id']])->order('weigh desc')->limit(4)->select();
		}
		$this->assign('hangyexinxi_type2',$hangyexinxi_type2);
		
		$type=$request->param('type/d',0);
		if($type==0){
			$list=Db::name('biaozhunbianzhi')->alias('b')->field('b.*,t.name as type_name')->join('biaozhuntype t','b.biaozhuntype_id=t.id','LEFT')->order('b.weigh desc')->paginate(15);
		}else{
			$list=Db::name('biaozhunbianzhi')->alias('b')->field('b.*,t.name as type_name')->join('biaozhuntype t','b.biaozhuntype_id=t.id','LEFT')->where('b.biaozhuntype_id',$type)->order('b.weigh desc')->paginate(15);
		}
		$this->assign('list',$list);
		
        return $this->view->fetch();
    }
	
	public function detail(Request $request)
	{	
		$id=$request->param('id/d',0);
		$rs=Db::name('biaozhunbianzhi')->where('id',$id)->find();
		if(is_null($rs)){
			$this->error('内容不存在');
		}
		Db::name('biaozhunbianzhi')->where('id',$id)->setInc('views');
		$this->assign('rs',$rs);
		$this->view->assign('title', __('标准编制-').$rs['title']);
		$this->assign('image',input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME').$rs['image']);
	    return $this->view->fetch();
	}
}
